//
//  smViewController.m
//  shimaoHouse
//
//  Created by amy zhang on 12-6-27.
//  Copyright (c) 2012年 yst. All rights reserved.
//

#import <QuartzCore/QuartzCore.h>
#import "smViewController.h"
#import "smloginController.h"


#import "SUPApplication.h"
#import "smMboSmMboDB.h"
#import "SUPConnectionProperties.h"
#import "SUPLoginCredentials.h"
#import "SUPConnectionProfile.h"
#import "SUPObjectList.h"
#import "smMboSmTbHouse.h"



@interface smViewController () <UITabBarDelegate,UITextFieldDelegate,MBProgressHUDDelegate>

{

NSTimer *timer;
UIImageView *splashImageView;
UINavigationController *nav;
//smloginController *myviewcontroller;
}

@property (nonatomic,retain) NSTimer *timer;
@property (nonatomic,retain) UIImageView *splashImageView;
@property (nonatomic,retain) UINavigationController *nav;
//@property (nonatomic,retain) smloginController *myviewcontroller;


@end

@implementation smViewController



@synthesize timer;
@synthesize splashImageView;
@synthesize nav;
//@synthesize myviewcontroller;

int flag;
NSTimer *timer;

smloginController* orderSearchController;

-(void) loadView {
    [super loadView];
    
        [self.navigationController.navigationBar setHidden:YES];
     
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    [self.navigationController.navigationBar setHidden:YES];
    
    // Do any additional setup after loading the view from its nib.
//    CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
//    UIView *view = [[UIView alloc] initWithFrame:appFrame];
//    view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
//    self.view = view;
    
    [self.view setBackgroundColor:[UIColor clearColor]];
    
    [self.tabBar setFrame:CGRectMake(0, self.view.bounds.size.height-77, self.view.bounds.size.width, 77)];
    
    flag = 0;
    
    splashImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"home.png"]];
    splashImageView.frame = CGRectMake(0, 0, 768, 1024);
    [self.view addSubview:splashImageView];
    
    orderSearchController = [[smloginController alloc] init];
    [self.view addSubview:orderSearchController.view];
    [orderSearchController.view setHidden:YES];
    
    timer = [NSTimer scheduledTimerWithTimeInterval:0.6 
                                             target:self 
                                           selector:@selector(addLabel) 
                                           userInfo:nil 
                                            repeats:YES];
    
//    myviewcontroller = [[smloginController alloc] init];
//    myviewcontroller.view.alpha = 0.0;
//    //[self.view addSubview:myviewcontroller.view];
//    nav = [[UINavigationController alloc] init];
//    [nav pushViewController:myviewcontroller animated:NO];
//    [self.view addSubview:nav.view];
    
    
    timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(finishedFading) userInfo:nil repeats:NO];
    
    
    
}


- (void)addLabel{
    
    flag++;
    if (flag <=4) {
        UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(200+ 100*flag, 600, 80, 80)];
        
        [label1 setTextAlignment:UITextAlignmentCenter];
        
        switch (flag) {
            case 1:
                label1.text = @"世";
                break;
            case 2:
                label1.text = @"贸";
                break;
            case 3:
                label1.text = @"房";
                break;
            case 4:
                label1.text = @"产";
                break;
                
            default:
                break;
        }
        
        label1.font = [UIFont systemFontOfSize:23];
        label1.textColor = [UIColor redColor];
        
        CALayer *layer = [label1 layer];
        [layer setMasksToBounds:YES];
        [layer setCornerRadius:5.0];
        [layer setBorderWidth:0.5];
        [layer setBorderColor:[[UIColor grayColor] CGColor]];
        
        [self.view addSubview:label1];
    }
    
}

- (void)fadeScreen
{
    [UIView beginAnimations:nil context:nil]; // begins animation block
    [UIView setAnimationDuration:0.75];        // sets animation duration
    [UIView setAnimationDelegate:self];        // sets delegate for this block
    [UIView setAnimationDidStopSelector:@selector(finishedFading)];   // calls the finishedFading method when the animation is done (or done fading out)    
    self.view.alpha = 0.8;       // Fades the alpha channel of this view to "0.0" over the animationDuration of "0.75" seconds
    [UIView commitAnimations];   // commits the animation block.  This Block is done.
}


- (void) finishedFading
{
    self.view.alpha = 0.5; 
    [UIView beginAnimations:nil context:nil]; // begins animation block
    [UIView setAnimationDuration:0.75];        // sets animation duration
    self.view.alpha = 1;   // fades the view to 1.0 alpha over 0.75 seconds
//    myviewcontroller.view.alpha = 1.0;
    [UIView commitAnimations];   // commits the animation block.  This Block is done.
    
    for(UIView *mylabelview in [self.view subviews])
    {
        if ([mylabelview isKindOfClass:[UILabel class]]) {
            [mylabelview removeFromSuperview];
        }
    }
    
    [splashImageView removeFromSuperview];
    
    //smloginController* orderSearchController = [[smloginController alloc] init];
    [orderSearchController.view setHidden:NO];
//    [self.navigationController pushViewController:orderSearchController animated:NO];
}


-(void)viewWillAppear:(BOOL)animated {
        

}



- (void)viewDidAppear:(BOOL)animated {

}



- (void)viewDidDisappear:(BOOL)animated {
    
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

@end

